﻿import pymysql

def get_list(sql,args):
    conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='t1', charset='utf8')
    # 创建游标
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

    # 执行SQL，并返回收影响行数
    cursor.execute(sql,args)

    result = cursor.fetchall()

    # print("result.title", result)

    # 关闭游标
    # print(result)
    cursor.close()
    # 关闭连接
    conn.close()
    return result

def get_one(sql,args):
    conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='t1', charset='utf8')
    # 创建游标
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

    # 执行SQL，并返回收影响行数
    cursor.execute(sql,args)

    result = cursor.fetchone()

    # print("result.title", result)

    # 关闭游标
    # print(result)
    cursor.close()
    # 关闭连接
    conn.close()
    return result

def modify(sql,args):

    conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='t1', charset='utf8')
    # 创建游标
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

    # 执行SQL，并返回收影响行数
    cursor.execute(sql,args)

    conn.commit()
    # 关闭游标
    # print(result)
    cursor.close()
    # 关闭连接
    conn.close()

